package com.example.studentmanager;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ShowStudent extends AppCompatActivity {
    ListView showlv;
    EditText query_xuehao;
    Button btnquery;
    private List<String> list;
    private ArrayAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_student);

        showlv = findViewById(R.id.showlv);
        query_xuehao = findViewById(R.id.query_xuehao);
        btnquery = findViewById(R.id.btnquery);

        btnquery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Student student = null;
                student = StudentDB.getStudentDB(ShowStudent.this).query(query_xuehao.getText().toString());
                if (student != null) {
                    list = new ArrayList<>();
                    list.add("学号： " + student.xuehao);
                    list.add("性别： " + student.gender);
                    list.add("地址： " + student.address);
                    list.add("电话： " + student.phone);
                    list.add("成绩： " + student.chengji);
                    adapter = new ArrayAdapter(ShowStudent.this, android.R.layout.simple_list_item_1, list);
                    showlv.setAdapter(adapter);
                    showlv.setVisibility(View.VISIBLE);
                } else {
                    showlv.setVisibility(View.GONE);
                    Toast.makeText(ShowStudent.this, "学号不存在，无此学生信息！", Toast.LENGTH_SHORT).show();
                }


            }
        });
    }
}